-
-
Notifications
You must be signed in to change notification settings - Fork 63
Fix MA0185 false-positive for nullable value types #995
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Co-authored-by: meziantou <[email protected]>
Co-authored-by: meziantou <[email protected]>
|
@copilot Test fails [xUnit.net 00:01:30.36] Meziantou.Analyzer.Test.Rules.UseIFormatProviderAnalyzerTests.NullableInt32ToStringWithoutCultureInfo_DisabledConfig [FAIL] Diagnostics: Source: Stack Trace: Error: Mismatch between number of diagnostics returned, expected "0" actual "1" |
…rmattableType Co-authored-by: meziantou <[email protected]>
Fixed in e2c59fe. The issue was that I modified Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
Fix MA0185 False-positive with
int?int?Root Cause
The MA0185 analyzer was using
CultureSensitiveOptions.Nonewhich doesn't unwrap nullable types. This causedint?to be checked asNullable<int>which doesn't implementIFormattable, leading to the false positive.Changes Made
SimplifyStringCreateWhenAllParametersAreCultureInvariantAnalyzerto useCultureSensitiveOptions.UnwrapNullableOfTinstead ofCultureSensitiveOptions.Noneint?are checked by their underlying type (int) which correctly identifies them as culture-sensitiveCultureSensitiveFormattingContext.IsFormattableType()which was breaking MA0011'sconsider_nullable_typesconfiguration optionStringCreateWithInvariantCulture_WithNullableInteger_NoDiagnostic- verifies fix forint?StringCreateWithInvariantCulture_WithNullableDouble_NoDiagnostic- verifies fix fordouble?Testing
NullableInt32ToStringWithoutCultureInfo_DisabledConfig)Why This Approach
The previous approach of always unwrapping in
IsFormattableTypebroke MA0011's behavior whenconsider_nullable_typesis false. The correct fix is to make MA0185 explicitly unwrap nullable types by using theUnwrapNullableOfToption, which respects the semantics of checking underlying types forstring.CreatewithInvariantCulture.Original prompt
int?#994💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.